package cn.thoughtworks.school.usercenter.controllers;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/metadata")
public class MetadataController {

    @Value("${spring.profiles.active:default}")
    private String springProfilesActive;

    @Value("${app.server:http://localhost:8080}")
    private String appServer;

    @RequestMapping(value = "", method = RequestMethod.GET)
    public Map<String, String> getMetadata() {
        Map<String, String> metadata = new HashMap<>();
        metadata.put("SPRING_ACTIVE_PROFILE", springProfilesActive);
        metadata.put("APP_SERVER", appServer);

        metadata.put("APP_VERSION", System.getenv("APP_VERSION"));

        return metadata;
    }
}
